﻿
#region USING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#endregion

namespace Learning.ConwaysGameOfLife
{
    public class Cell
    {
		#region Constructors (1) 

        public Cell(Cordinate cordinate, CellState state)
        {
            this.Cordinate = cordinate;
            this.State = state;
        }

		#endregion Constructors 

		#region Properties (3) 

        public Cordinate Cordinate { get; set; }

        public CellState State { get; set; }

		#endregion Properties 

		#region Methods (5) 

		// Public Methods (5) 

        public static bool operator !=(Cell rhs, Cell lhs)
        {
            // Null check
            if (Object.ReferenceEquals(rhs, null) || Object.ReferenceEquals(lhs, null))
            {
                if (Object.ReferenceEquals(rhs, null) && Object.ReferenceEquals(lhs, null))
                {
                    // Both are null.  They do equal each other
                    return false;
                }

                // Only 1 is null the other is not so they do not equal
                return true;
            }

            return !rhs.Equals(lhs);
        }

        public static bool operator ==(Cell rhs, Cell lhs)
        {
            // Null check
            if (Object.ReferenceEquals(rhs, null) || Object.ReferenceEquals(lhs, null))
            {
                if (Object.ReferenceEquals(rhs, null) && Object.ReferenceEquals(lhs, null))
                {
                    // Both are null.  They do equal each other
                    return true;
                }

                // Only 1 is null the other is not so they do not equal
                return false;
            }

            return rhs.Equals(lhs);
        }

        public Cell Copy()
        {
            return new Cell(this.Cordinate, this.State);
       }

         public override bool Equals(object obj)
        {
            Cell otherObj = obj as Cell;

            if (otherObj == null)
            {
                return false;
            }

            return this.Cordinate == otherObj.Cordinate && this.State == otherObj.State;
        }

        public override int GetHashCode()
        {
            return string.Format("{0}{1}", this.Cordinate, this.State).GetHashCode();
        }

		#endregion Methods 
    }
}